/**
 * create by young (young2f@outlook.com) on 2020/12/4
 * 采购物料退货单
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    orderCode: { type: String, _type: 'string', title: '销售退货单编码', required: true },
    salesOrderCode: {
      type: String,
      _type: 'string',
      title: '订单编码',
      enableArea: [ 'table', 'search', 'detail', ],
    },

    division: { type: String, _type: 'string', title: '销售公司', enableArea: [ 'search' ], },

    prodCode: {
      type: String,
      _type: 'string',
      title: '商品编码',
      required: true,
      enableArea: [ 'table', 'input', 'detail', ]
    },
    prodName: { type: 'string', _type: 'string', title: '物料名称', enableArea: [ 'table', 'input', 'detail', ], },

    customer: { type: String, _type: 'string', title: '客户名称', enableArea: [ 'table', 'input', 'detail', ] },
    customerCode: { type: String, _type: 'string', title: '客户编码', enableArea: [ 'detail', ], },
    taxRate: { type: String, _type: 'string', title: '税率', enableArea: [ 'detail', ], },
    label: { type: String, _type: 'string', title: '标签', enableArea: [ 'detail', ], },
    pkg: { type: String, _type: 'string', title: '包装', enableArea: [ 'detail', ], },
    deliverWay: { type: String, _type: 'string', title: '发货方式', enableArea: [ 'detail', ], },

    price: { type: Number, _type: 'number', title: '单价', enableArea: [ 'table', 'search', 'detail' ], },
    laborFee: { type: Number, _type: 'number', title: '劳务费用', enableArea: [ 'table', 'search', 'detail' ], },
    taxDeductionPointForLaborCosts: { type: Number, _type: 'number', title: '劳务扣税点', enableArea: [ 'table', 'search', 'detail' ], },
    pkgFee: { type: Number, _type: 'number', title: '包装费用', enableArea: [ 'table', 'search', 'detail' ], },
    shippingFee: { type: Number, _type: 'number', title: '运费', enableArea: [ 'table', 'search', 'detail' ], },
    count: { type: Number, _type: 'number', title: '补货数量', enableArea: [ 'table', 'search', 'detail' ], },
    outboundDate: { type: Date, _type: 'date', title: '补货出库时间', enableArea: [ 'table', 'search', 'detail' ], },
    outboundCount: { type: Number, _type: 'number', title: '补货出库数量', enableArea: [ 'table', 'search', 'detail' ], },
    materials:{type:Array, _type: 'array',title: '原料清单', },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('SalesReplenishRecord', _schema);
};
